<!DOCTYPE HTML>
<html>
  <head>
	<?php echo Yaf_View_Simple::render("header.phtml"); ?>
    <script type="text/javascript" src="/asset/admin/js/fileinput.js"></script>
    <link type="text/css" rel="stylesheet" href="/asset/admin/css/fileinput.css" />    
  </head>
  <body>
	<?php echo Yaf_View_Simple::render("menu.phtml"); ?>
	<div class="container">
      <div class="page-header" >
        <div class="col-lg-8" >
          Edit Category!
        </div>
        <div class="col-lg-4 text-right" >
          <a href="/admin/category/create" class="btn btn-primary" >New</a>
          <a href="/admin/category/edit?id=<?php echo $data['id'] ?>" class="btn btn-primary" >Edit Next</a>
        </div>
        <div class="clearfix" ></div>
      </div>
		<form role="form" class="form-horizontal" method ="post" action="update" id="beform">
		  <fieldset>
			<div class="form-group">
			  <label class="col-lg-2 control-label">ID:</label>
			  <div class="col-lg-2">
		        <input type="text" name="id" class="form-control" id="id" value="<?php echo $data['id']; ?>" readonly/>
			  </div>
			</div>
			<div class="form-group">
			  <label class="control-label col-lg-2">Parent Category</label>
			  <div class="controls col-lg-6">
				<select class="form-control" name="fid">
				  <option value="0">The Root</option>
				  <?php foreach($categorys as $value){ ?>
                  <?php if($value['id'] == $data['fid']){ ?>
				  <option value="<?php echo $value['id']; ?>" <?php echo 'selected'; ?>><?php echo $value['name'] ?></option>
                  <?php }else{ ?>
				  <option value="<?php echo $value['id']; ?>"><?php echo $value['name'] ?></option>
				  <?php }} ?>
				</select>
			  </div>
			</div>
            
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="name">Name:</label>
			  <div class="col-lg-6">
				<input type="text" name="name" class="form-control" id="name" value="<?php echo $data['name']; ?>"/>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="link">Link:</label>
			  <div class="col-lg-6">
				<input type="text" name="link" class="form-control" id="link" value="<?php echo $data['link']; ?>"/>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="sort">Sort:</label>
			  <div class="col-lg-6">
				<input type="text" name="sort" class="form-control" id="sort" value="<?php echo $data['sort']; ?>"/>
			  </div>
			</div>            
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="description">Description:</label>
			  <div class="col-lg-6">
				<textarea name="description" rows="5" id="description" class="form-control"><?php echo $data['description']; ?></textarea>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" >Image:</label>
			  <div class="col-lg-10">
				<input type="hidden" name="image" id="image" class="form-control" value="<?php echo $data['image']; ?>"/>
                <input id="input-id" type="file" class="file" data-preview-file-type="text" >
			  </div>
			</div>            						
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="description"></label>
			  <div class="col-lg-6">
		        <a  href="javascript:def.submit('#beform',null)" class="btn btn-primary">Submit</a>
			  </div>
			</div>
		  </fieldset>
		</form>
	</div> <!-- ./container	 -->
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modellabel" aria-hidden="true">
	  <div class="modal-dialog">
		<div class="modal-content">
		  <div class="modal-header bg-default">
			<div class="modal-title" id="modallabel">
			  <h5 class="text-primary">Signal</h5>
			</div>
		  </div>
		  <div class="modal-body bg-primary">
			
		  </div>
		  <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Close
			</button>
		  </div>
		</div><!-- /.modal-content -->
	  </div><!-- /.modal -->
	</div>		
	<?php echo Yaf_View_Simple::render("footer.phtml"); ?>
    <script type="text/javascript">
     $("#input-id").fileinput({
         initialPreview: [
             '<img src="<?php echo $data['image']; ?>" style="width:100%"/>'
         ],
         uploadUrl: '/admin/category/upfile',
         showUpload: true,
         showCaption: false,
         browseClass: "btn btn-primary",
         previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
         allowedPreviewTypes: ['image'],
         allowedFileTypes: ['image'],
         allowedFileExtensions:  ['jpg', 'png','gif'],             
     }).on('fileuploaded', function(event, data) {
         var file = data.response.file_data;
         image = '/'+file.root_path+'/'+file.save_path+file.save_name;
         $("#image").val(image);
     });
    </script>
  </body>
</html>
